package com.im.manage.handler;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.im.api.bean.ServerAddress;
import com.im.manage.IMConstants;
import com.im.manage.bean.Head;
import com.im.manage.bean.Message;
import com.only.common.lib.util.HttpClient3Util;
import com.only.common.lib.util.OnlyJsonUtil;

/**
 * @author: XiaHui
 * @date: 2016年10月20日 下午4:05:02
 */
public class AuthHandler {

	String baseUrl = IMConstants.baseUrl;

	public String authUser(ServerAddress userData) {
		String result = null;
		Head head = new Head();
		head.setAction("auth");
		head.setMethod("authUser");

		Message message = new Message();
		message.setHead(head);
		message.put("userData", userData);
		String data = OnlyJsonUtil.objectToJson(message);

		JSONObject auth = new JSONObject();
		auth.put("id", "own-000001");
		auth.put("key", "kkkyyyttt");
		try {
			// String url ="http://www.jiaoyijie.cn/immgr/web/api.do";
			// String url ="http://192.168.1.200:9080/immgr/web/api.do";
			String url = baseUrl + "/web/api.do";
			Map<String, String> dataMap = new HashMap<String, String>();
			dataMap.put("auth", auth.toJSONString());
			dataMap.put("data", data);
			result = HttpClient3Util.post(url, dataMap);
		} catch (Exception e) {
			// e.printStackTrace();
		}
		return result;
	}
}
